#ifndef LPFCONFIG_H
#define LPFCONFIG_H

#include "filterconfig.h"
#include "dmenum.h"

namespace LpfConfig {


namespace BesselFilter {
// Bessel滤波器参数配置表（斜率→频率缩放因子+Qa+Qb）
struct BesselParam {
    Slope slope;
    double scale;       // 频率缩放因子（原LPF_fre = LPF_fre / scale）
    std::array<double, 4> Qa;// Qa参数数组
    std::array<double, 4> Qb;// Qb参数数组
};

// 不同斜率对应的Bessel参数
constexpr std::array<BesselParam, 7> LPF_BESSEL = {{
    // 斜率          频率缩放        Qa[0..3]                Qb[0..3]
    {Slope::Oct_12dB, 1.3616541287, {1.0, 0.0, 0.0, 0.0},   {0.3333333333, 0.0, 0.0, 0.0}},
    // {Slope::Oct_18dB, 1.75567236868, {0.5693712514, 0.430628846, 0.0, 0.0}, {0.154812441, 0.0, 0.0, 0.0}},
    {Slope::Oct_24dB, 2.1139176749, {0.369, 0.6278294896, 0.0, 0.0}, {0.087858766, 0.109408, 0.0, 0.0}},
    // {Slope::Oct_30dB, 1.0, {0.6656, 1.1402, 0.6216, 0.0}, {0.0, 0.4128, 0.3245, 0.0}},
    {Slope::Oct_36dB, 1.0, {1.2217, 0.9686, 0.5131, 0.0}, {0.3887, 0.3505, 0.2756, 0.0}},
    // {Slope::Oct_42dB, 1.0, {0.5937, 1.0944, 0.8304, 0.4332}, {0.0, 0.3395, 0.3011, 0.2381}},
    {Slope::Oct_48dB, 3.17961723751, {0.117235677, 0.226516664, 0.3067559, 0.3494916166}, {0.02064747, 0.0259273886, 0.0294683265, 0.031272257}}
}};

// 计算Bessel滤波器的二阶节系数
BiquadCoeffs calculateCoeffs(double cutoffFreq, Slope slope);

}


namespace LrButterFilter {

struct LrButterParam
{
    Slope slope;                        // 倍频程斜率
    std::array<double, 4> q;            // 4个滤波器节的Q值（最大48dB=4个二阶节）
};

constexpr std::array<LrButterParam, 7> LPF_BUTTER_WORTH = {{
    {Slope::Oct_12dB, {0.70422535, 0.0, 0.0, 0.0}},
    // {Slope::Oct_18dB, {1.0, 0.5, 0.0, 0.0}},
    {Slope::Oct_24dB, {0.92592593, 0.38167939, 0.0, 0.0}},
    // {Slope::Oct_30dB, {1.0, 0.8064616129, 0.3086417953, 0.0}},
    {Slope::Oct_36dB, {0.96153846, 0.70422535211, 0.2590673575, 0.0}},
    // {Slope::Oct_42dB, {1.0, 0.90909090909, 0.625, 0.2222222222}},
    {Slope::Oct_48dB, {0.98039216, 0.83333333, 0.55555556, 0.1953125}}
}};

constexpr std::array<LrButterParam, 7> LPF_LINKWITZ_RILEY = {{
    {Slope::Oct_12dB, {1.0, 0.0, 0.0, 0.0}},
    // {Slope::Oct_18dB, {1.0, 0.70422535211, 0.0, 0.0}},
    {Slope::Oct_24dB, {0.70422535211, 0.70422535211, 0.0, 0.0}},
    // {Slope::Oct_30dB, {1.0, 0.62, 0.62, 0.0}},
    {Slope::Oct_36dB, {1.0, 0.5, 0.5, 0.0}},
    // {Slope::Oct_42dB, {1.0, 0.4531343150, 0.92592592593, 0.4531343150}},
    {Slope::Oct_48dB, {0.92592592593, 0.3731343150, 0.92592592593, 0.3731343150}}
}};

// 计算LR/Butterworth滤波器的二阶节系数
BiquadCoeffs calculateCoeffs(double cutoffFreq, PfType type, Slope slope);


}

}

#endif // LPFCONFIG_H
